package com.dragon.repository.mapper;

import com.dragon.repository.entity.InoutProduct;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 物品出入关联表 Mapper 接口
 * </p>
 *
 * @author sy
 * @since 2023-11-14
 */
@Mapper
public interface InoutProductMapper extends BaseMapper<InoutProduct> {

    /**
     * 根据主表id 获取（出入库产品）子表list
     * @param id 出入库id
     * @return
     */
    @Select("SELECT M.* FROM (SELECT " +
            " a.*, " +
            " p.spu_specification AS specificationName, " +
            " p.name AS productSpuName, " +
            " pu.name AS unitName " +
            "FROM dragon_inout_product a " +
            "LEFT JOIN dragon_product p ON a.claims_product_id = p.id  " +
            "LEFT JOIN dragon_product_unit pu ON a.unit_id = pu.id ) M WHERE M.inout_id = #{id} ")
    List<InoutProduct> selectListByInoutId(Integer id);

}
